using System;
using SharpWind.Resources.Managers;
using Microsoft.Xna.Framework.Audio;
using SharpWind.Helpers;
using System.IO;

namespace SharpWind.Sound
{
	public class SoundManager : ResourceManager<Sound>
	{
		#region Fields

		private AudioEngine audioEngine = null;

		private WaveBank waveBank = null;

		private SoundBank soundBank = null;

		private AudioCategory defaultCategory;

		private AudioCategory musicCategory;

		private AudioListener audioListener = null;

		private AudioEmitter audioEmiter = null;

		#endregion

		#region Constructor

		internal SoundManager()
		{
			try
			{
				this.audioEngine = new AudioEngine( Path.Combine( Directories.Sounds, "SharpWindSounds.xgs" ) );
				this.waveBank	 = new WaveBank( this.audioEngine, Path.Combine( Directories.Sounds, "Wave Bank.xwb" ) );
				if( this.waveBank != null )
				{
					this.soundBank = new SoundBank( this.audioEngine, Path.Combine( Directories.Sounds, "Sound Bank.xsb" ) );
				}

				this.defaultCategory = this.audioEngine.GetCategory( "Default" );
				this.musicCategory	 = this.audioEngine.GetCategory( "Music" );

				this.audioListener	 = new AudioListener();
				this.audioEmiter	 = new AudioEmitter();
			}
			catch( NoAudioHardwareException ex )
			{
			}
		}

		#endregion

		#region Methods

		internal void Update()
		{
			this.audioEngine.Update();
		}

		#endregion

		#region Properties

		public AudioListener AudioListener
		{
			get
			{
				return this.audioListener;
			}
		}

		internal SoundBank SoundBank
		{
			get
			{
				return this.soundBank;
			}
		}

		internal AudioEmitter AudioEmiter
		{
			get
			{
				return this.audioEmiter;
			}
		}

		#endregion
	}
}
